package com.joe.weather.tool;

import java.util.ArrayList;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;

public class SMSUtil
{
	public static void sendMessage(Context context, String smsDest, String smsContent)
	{
		SmsManager smsManager = SmsManager.getDefault();
		ArrayList<PendingIntent> sentIntents;
		
		if(smsContent.length() > 70)
		{
			ArrayList<String> msgs = smsManager.divideMessage(smsContent);
			sentIntents = new ArrayList<PendingIntent>(msgs.size());
			for (int i = 0; i < msgs.size(); i++)
			{
				sentIntents.add(PendingIntent.getBroadcast(context, i, new Intent(), 0));
			}
			
			smsManager.sendMultipartTextMessage(smsDest, null, msgs, sentIntents, null);
		}
		else
		{
			sentIntents = new ArrayList<PendingIntent>(1);
			sentIntents.add(PendingIntent.getBroadcast(context, 0, new Intent(), 0));
			
			smsManager.sendTextMessage(smsDest, null, smsContent, sentIntents.get(0), null);
		}
	}
}
